package by.grsu.na.page.sample;

import java.util.List;

import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.markup.repeater.data.DataView;
import org.apache.wicket.markup.repeater.data.ListDataProvider;

import by.grsu.na.app.MyWebApplication;
import by.grsu.na.dao.impl.BlackClientDao;
import by.grsu.na.entity.BlackClient;

public class BlackClientsListPage extends WebPage {

	public BlackClientsListPage() {
		super();
		
	
		final BlackClientDao blackClientDao = new BlackClientDao(MyWebApplication.DATA_XML_FOLDER);

		final List<BlackClient> allBlackClients = blackClientDao.getAll(); 

		add(new DataView<BlackClient>("table-rows", new ListDataProvider<BlackClient>(allBlackClients)) {
			@Override
			protected void populateItem(final Item<BlackClient> item) {
				final BlackClient blackClient = item.getModelObject();
				item.add(new Label("id", blackClient.getId()));
				item.add(new Label("clientName", blackClient.getClientName()));
				item.add(new Label("clientLogin", blackClient.getClientLogin()));
				item.add(new Label("clientPasword", blackClient.getClientPasword()));
				
				
				item.add(new Link("delete2Link") {
					@Override
					public void onClick() {

						blackClientDao.delete(blackClient.getId());
						setResponsePage(new BlackClientsListPage());
						
					}
				});
			}
		});

		
	}
}